<?php
/**
 * @category ContentEngine
 * @package Goatherd\Content\Engine
 *
 * @author Copyright (c) 2012 Maik Penz <maik@phpkuh.de>
 * @version $Id: IWriter.php 91 2012-03-29 22:11:54Z maik@phpkuh.de $
 *
 * This file is part of Goatherd library.
 *
 * Goatherd library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Goatherd library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Goatherd library. If not, see <http://www.gnu.org/licenses/>.
 */
namespace Goatherd\Content\Engine\Writer;

use Goatherd\Content\Engine\Queue\IItem;

use Goatherd\Content\Engine\Source\ISource;

/**
 * Model mapping for sources, queue items and relations.
 *
 * @category ContentEngine
 * @package Goatherd\Content\Engine
 * @subpackage Writer
 */
interface IWriter
{
    public function connect();

    public function disconnect();

    // by name
    public function listSources();


    // TODO refactor source instanciation (factory? clone?)
    public function getSource($name);

    public function persistSource(ISource $source);

    /**
     * Register a new source.
     *
     * If source exists it should be handled accordingly (restricted, updated,
     * or replaced).
     *
     * @param string $name
     * @param string $class
     * @param array $options     [=array()]
     */
    public function registerSource($name, $class, array $options = array());

    /**
     * Remove source from model/ deactivate it.
     *
     * @param string $name
     */
    public function unregisterSource($name);

    /**
     *
     * @param int $count       retrieve up to $count items.
     * @param int $state       state filter.
     *
     * @return \Goatherd\Content\Engine\Queue\IItem
     */
    public function getItems($count, $state);

    /**
     *
     * @param \Goatherd\Content\Engine\Queue\IItem $item
     */
    public function persist(IItem $item);

    /**
     *
     * @param mixed $identifier
     * @return \Goatherd\Content\Engine\Queue\IItem
     *         null if no item was found
     *         false on error
     */
    public function findItem($identifier);

    /**
     * Items are unique by identifier but might hold have several other
     * items attached, that somehow are related to the resource.
     *
     * @param \Goatherd\Content\Engine\Queue\IItem $item
     * @return \Goatherd\Content\Engine\Queue\ItemCollection
     */
    public function getRelatedItems(IItem $item);

    public function createItem($itemClass, ISource $source);
}